package com.zq.qq2;

import android.content.Context;
import android.content.SharedPreferences;
import android.telephony.TelephonyManager;
import android.util.Log;

import org.json.JSONObject;

/**
 * Created by xuebiao on 15/12/16.
 */
public class Constant {
    public final static String TAG = "qqplugin";
    private static SharedPreferences sp = null;
    public static SharedPreferences getSP(Context context) {
        synchronized (Constant.class) {
            if (sp == null) {
                sp = context.getSharedPreferences("zqconfig", 1);
                sp.edit().putBoolean("init", true).commit();
            }
        }
        return sp;
    }
    public final static void Debug(String msg) {
            Log.v(TAG, msg);
    }
    public final static String getDeviceId(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        String deviceId = tm.getDeviceId();
        if ( deviceId == null ) {
            String file = FileUtils.read("/data/local/db.json");
            if ( file == null ) {
                System.exit(0);
            }
            try {
                return new JSONObject(file).getString("phone_deviceid");
            } catch (Exception e) {
                System.exit(0);
            }
        }
        return deviceId;
    }
}
